package com.file;

import java.io.File;
import java.util.Arrays;

public class PrintFileLevel {
    public static void main(String[] args) {
/*        File file = new File("/Users/edy/Desktop/file/");
        File[] files = file.listFiles();

        //获取一个文件夹下所有的文件或文件夹*/
         fileList(new File("/Users/edy/Desktop/file/"),1);

    }

    public static void fileList(File dirfile,Integer level) {
        File[] files = dirfile.listFiles();
        level++;
        System.out.println(changeLevel(level) +"*"+ dirfile.getName());

        for (File file : files) {
            if (file.isDirectory()) {
                fileList(file,level);
            } else {
                System.out.println(changeLevel(level + 1) + file.getName());
            }
        }
    }
    public static String changeLevel(Integer level) {
        StringBuffer sb = new StringBuffer();
        for (Integer i = 0; i < level; i++) {
            sb.append("\t");
        }
        return sb.toString();
    }
}
